package cn.git.demo.controller.product;

import cn.git.demo.pojo.Brand;
import cn.git.demo.service.BrandService;
import cn.itcast.common.page.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@Transactional
public class BrandController {


    @Autowired
    private BrandService brandService;

    @RequestMapping(value = "/brand/list.do")
    public String list(String name,Integer pageNo,Integer isDisplay,Model model){

        Pagination pagination = brandService.selectPaginationByQuery(name,isDisplay,pageNo);

        model.addAttribute("pagination",pagination);

        model.addAttribute("name",name);

        if(isDisplay!=null){
            model.addAttribute("isDisplay",isDisplay);
        }else {
            model.addAttribute("isDisplay",1);
        }

        return "brand/list";

    }
    @RequestMapping(value = "/brand/toEdit.do")
    public String toEdit(Long id,Model model){

        Brand brand = brandService.selectBrandById(id);

        model.addAttribute("brand",brand);

        return "brand/edit";
    }


}
